package cn.changeforyou.web.controller;

import cn.changeforyou.web.dao.UserDao;
import cn.changeforyou.web.entity.TestConditionTypeCondition;
import cn.changeforyou.web.entity.User;
import cn.changeforyou.web.entity.UserDTO;
import cn.changeforyou.web.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhyu
 * @date 2022/03/25 16:43
 */
@RestController
@RequestMapping("update")
public class UpdateController {

    @Autowired
    private UserDao userDao;

    @Autowired
    private UserService userService;

    @PostMapping("/entity")
    public int entity(@RequestBody User user) {
        return userDao.updateEntity(user);
    }

    @PostMapping("/dto")
    public int dto(@RequestBody UserDTO dto) {
        return userDao.updateDTO(dto);
    }

    @PostMapping("/entityIgnoreNull")
    public int entityIgnoreNull(@RequestBody User user) {
        return userDao.updateEntityIgnoreNull(user);
    }

    @PostMapping("/dtoIgnoreNull")
    public int dtoIgnoreNull(@RequestBody UserDTO dto) {
        return userDao.updateDTOIgnoreNull(dto);
    }

    @PostMapping("/entityCondition")
    public int entityCondition(@RequestBody TestConditionTypeCondition condition) {
        User user = new User();
        user.setAvailable(false);
        return userDao.updateEntityByCondition(user, condition);
    }

    @PostMapping("/dtoCondition")
    public int dtoCondition(@RequestBody TestConditionTypeCondition condition) {
        UserDTO user = new UserDTO();
        user.setPassword("aaaaaaaaaaaaaaazzzzzzzzzzzzzzzzzzz");
        return userDao.updateDTOByCondition(user, condition);
    }
}
